#coding=utf-8

import re

from Model.MZCCSingleLineRuleItem import *
from Model.MZCCProblemItem import *
from Model.MZCCLineCheckContext import *
from Config.MZCCSpecialRuleHeader import *

from MZCCCheckerSupport import *

'''
' 单行规则检查
' 输入：
'  ruleItem : 规则项1
'  lineContext : 当前行检查上下文
' 输出：
'  问题项（MZCCProblemItem, 0或1个）
'''
def mzccSingleRuleCheck(ruleItem, lineContext):

	# 1：有问题 0：无问题
	checkResult = 0;

	if 0 != len(ruleItem.udCheckFuncName):
		if False == eval(ruleItem.udCheckFuncName)(lineContext):
			checkResult = 1;
	else:
		# 问题检查
		results = mzccRegex(lineContext.curLine, ruleItem.rejectRe)
		if 0 != len(results):
			checkResult = 1;

	problemItem = None;
	if 1 == checkResult:
		problemItem = MZCCProblemItem();
		problemItem.lineNum = lineContext.curLineNum;
		problemItem.desc = ruleItem.desc;
		problemItem.ruleId = ruleItem.ruleId;

	return problemItem;


